package com.administrator.scoreManageSys.service.impl;

import com.administrator.scoreManageSys.mapper.course.TeachCourseMapper;
import com.administrator.scoreManageSys.service.TeachCourseService;
import com.administrator.scoreManageSys.utils.ResultUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zsh
 * @date 2022/03/25/ 15:37
 */
@Service
public  class TeachCourseServiceImpl implements TeachCourseService {
    @Resource
    private TeachCourseMapper teachCourseMapper;

    @Resource
    private ResultUtils resultUtils;

    /**
     * 获取授课列表
     *
     * @param pageNum     当前页
     * @param pageSize    页大小
     * @param teacherName 查询教师姓名
     * @return 授课列表
     */
    @Override
    public JSONObject courseList(Integer pageNum, Integer pageSize, String teacherName) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = teachCourseMapper.courseList(teacherName);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return resultUtils.resultSuccessData(pageInfo);
    }


    /**
     * 添加授课信息
     *
     * @param userId    操作用户id
     * @param classId   授课班级
     * @param subject   授课科目
     * @param teachUser 授课教师
     * @return 操作结果
     */
    @Override
    public JSONObject courseAdd(Long userId, Integer classId, Integer subject, Integer teachUser) {
        long createTime = System.currentTimeMillis();
        teachCourseMapper.courseAdd(userId, createTime, classId, subject, teachUser);
        return resultUtils.resultSuccess();
    }

    /**
     * 根据id修改授课信息
     *
     * @param id        授课id
     * @param classId   授课班级
     * @param subject   授课科目
     * @param teachUser 授课教师
     * @return 操作结果
     */
    @Override
    public JSONObject courseUpdate(Integer id, Integer classId, Integer subject,  Integer teachUser) {
        teachCourseMapper.courseUpdate(id, classId, subject, teachUser);
        return resultUtils.resultSuccess();
    }

    /**
     * 根据id删除授课信息
     *
     * @param id 授课信息id
     * @return 操作结果
     */
    @Override
    public JSONObject courseDelete(Integer id) {
        teachCourseMapper.courseDelete(id);
        return resultUtils.resultSuccess();
    }

    /**
     * 添加考试课程信息
     *
     * @param season  考季id
     * @param classId 班级id
     * @param subject 科目id
     * @param name    考试课程名称
     * @param userId  操作人id
     * @return 操作结果
     */
    @Override
    public JSONObject examAdd(Integer season, Integer classId, Integer subject, String name, Long userId) {
        long createTime = System.currentTimeMillis();
        teachCourseMapper.examAdd(season,classId,subject,name,userId,createTime);
        return resultUtils.resultSuccess();
    }

    /**
     * 获取考试课程信息
     *
     * @param pageNum  当前页
     * @param pageSize 页大小
     * @param season   考季id
     * @param subject  科目
     * @param name     考试名次
     * @return 课程列表
     */
    @Override
    public JSONObject examList(Integer pageNum, Integer pageSize, Integer season, Integer subject, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list =   teachCourseMapper.examList(season,subject,name);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return resultUtils.resultSuccessData(pageInfo);
    }

    /**
     * 根据id修改考试管理
     *
     * @param id      考试管理id
     * @param classId 班级id
     * @param subject 科目id
     * @param season  考季id
     * @param name    考试管理名
     * @return 操作结果
     */
    @Override
    public JSONObject examUpdate(Integer id, Integer classId, Integer subject, Integer season, String name) {
        teachCourseMapper.examUpdate(season,classId,subject,name,id);
        return resultUtils.resultSuccess();
    }

    /**
     * 根据id删除考试管理
     *
     * @param id 考试id
     * @return 操作结果
     */
    @Override
    public JSONObject examDelete(Integer id) {
        teachCourseMapper.examDelete(id);
        return resultUtils.resultSuccess();
    }

    /**
     * 添加任课教师信息
     *
     * @param teacherId 教师id
     * @param subject   科目id
     * @param userId    操作人id
     * @return 操作结果
     */
    @Override
    public JSONObject theTeacherAdd(Integer teacherId, Integer subject, Long userId) {
        long createTime = System.currentTimeMillis();
        teachCourseMapper.theTeacherAdd(teacherId,subject,userId,createTime);
        return resultUtils.resultSuccess();
    }

    /**
     * 获取任课教师信息列表
     *
     * @param pageNum  当前页
     * @param pageSize 页大小
     * @param subject  科目
     * @param name     老师姓名
     * @return 列表
     */
    @Override
    public JSONObject theTeacherList(Integer pageNum, Integer pageSize, Integer subject, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list =   teachCourseMapper.theTeacherList(subject,name);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return resultUtils.resultSuccessData(pageInfo);
    }

    /**
     * 修改任课教师信息
     *
     * @param teacherId 任课教师id
     * @param subject   任课教师科目
     * @param id        修改id
     * @return 操作结果
     */
    @Override
    public JSONObject theTeacherUpdate(Integer teacherId, Integer subject, Integer id) {
        teachCourseMapper.theTeacherUpdate(teacherId,subject,id);
        return resultUtils.resultSuccess();
    }

    /**
     * 删除任课教师
     *
     * @param id 删除任课教师id
     * @return 操作结果
     */
    @Override
    public JSONObject theTeacherDelete(Integer id) {
        teachCourseMapper.theTeacherDelete(id);
        return resultUtils.resultSuccess();
    }


}
